﻿// -----------------------------------------------------------------------
// <copyright file="CommonImpl.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

using System.Collections.Generic;
using System.Data.Common;
using StampController.BL.Models;
using StampController.Core;

namespace StampController.BL
{
    /// <summary>
    ///     TODO: Update summary.
    /// </summary>
    public class CommonImpl
    {
        public IList<StampModel> GetStampList()
        {
            var list = new List<StampModel>();
            using (var dbHelper = new DbHelper())
            {
                using (DbDataReader reader = dbHelper.ExecuteReader("SELECT StampID, Name, Remark FROM Stamp"))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            list.Add(new StampModel
                            {
                                StampID = reader.Get<int>(0),
                                Name = reader.GetString(1)
                            });
                        }
                    }

                    reader.Close();
                }

                return list;
            }
        }

        public IList<StampTypeModel> GetStampTypeList()
        {
            var list = new List<StampTypeModel>();
            using (var dbHelper = new DbHelper())
            {
                using (DbDataReader reader = dbHelper.ExecuteReader("SELECT STID, Name, Remark FROM StampType"))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            list.Add(new StampTypeModel
                            {
                                STID = reader.Get<int>(0),
                                Name = reader.GetString(1)
                            });
                        }
                    }

                    reader.Close();
                }

                return list;
            }
        }

        public IList<RequiredTypeModel> GetRequiredTypeList()
        {
            var list = new List<RequiredTypeModel>();
            using (var dbHelper = new DbHelper())
            {
                using (DbDataReader reader = dbHelper.ExecuteReader("SELECT RequiredTypeID, Name, Remark FROM RequiredType"))
                {
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            list.Add(new RequiredTypeModel
                            {
                                RequiredTypeID = reader.Get<int>(0),
                                Name = reader.GetString(1)
                            });
                        }
                    }

                    reader.Close();
                }

                return list;
            }
        }
    }
}